<?php echo $header; ?>

<div id="content" class="w-content detailpage">
    <div class="w-content clearfix">
        <div class="eachBox undepages produkter-3">
            <div class="wrap-top clearfix">
                <ul class="breakcum">
                    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
                        <?php if($breadcrumb['href']) { ?>
                            <li><a href="<?php echo $breadcrumb['href']; ?>" ><?php echo $breadcrumb['text']; ?></a></li>
                        <?php }else{ ?>
                            <li><a href="#"><?php echo $breadcrumb['text']; ?></a></li>
                        <?php } ?>
                    <?php } ?>
                </ul>
            </div>
            <!--wrap-top-->
            <h4 class="box_tt"><?php echo $heading_title; ?></h4>
            <!--title-->
            <div class="col-detail-left">
                <div class="clearfix wrapZoom">
                      <a id="imgmax" href="<?php echo $full; ?>" class="jqzoom" rel='gal1' title="<?php echo $heading_title; ?>" >
                          <img src="<?php echo $thumb; ?>"  title="<?php echo $heading_title; ?>" style=""/>
                      </a>
                </div>
                <div class="wrapbtnZoom clearfix" ><a class="fancybox-big btnZoom"  href="" rel="rel-big"> </a> </div>
                <div class="clearfix">
                    <?php if ($images) { ?>
                        <?php $i = 0; $count = count($images); ?>
                        <ul id="thumblist" class="clearfix" >
                            <?php foreach ($images as $image) { ?>
                                <?php $i++; ?>
                                <li>
                                    <a <?php if($i=='1'){ ?>class="zoomThumbActive" <?php }?> href='javascript:void(0);' rel="{gallery: 'gal1', smallimage: '<?php echo $image['thumb']; ?>',largeimage: '<?php echo $image['full']; ?>'}"> <img src="<?php echo $image['thumb']; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>"/></a>
                                </li>
                            <?php } ?>
                        </ul>
                    <?php } ?>
                </div>
                 <div class="left-button clearfix">
                    <a class="leftbt btn-facebook" href="#">
                        <iframe src="//www.facebook.com/plugins/like.php?locale=da_DK&amp;href=<?php echo $current_url; ?>&amp;send=false&amp;layout=button_count&amp;width=150&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=tahoma&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:21px;" allowTransparency="true"></iframe>
                    </a>
                    <a id="tell_friend_btn" class="leftbt btn-tipenven fancybox" href="#ppTipenven">
                        <img src="catalog/view/theme/<?php echo $template; ?>/images/tipenven-mb.png"/>
                    </a>
                </div>
            </div>
            <!--col-detail-left-->
            <div class="col-detail-right">
                <?php echo $description; ?>
                <div class="r-price clearfix">
                    <div class="prod-price">
                        <?php if(!empty($discounts) || $discount){ ?>
                            <div class="clearfix"><label>Vejl. pris:</label><span class="price-old"><?php echo $price; ?></span></div>
                            <div class="clearfix"><label>Spar:</label><span class="price-spar"><?php echo $save_price?></span></div>
                            <div class="clearfix"><label>Tilbud:</label><span class="price-new"><?php echo $discount; ?></span></div>
                        <?php }else{ ?>
                            <div class="clearfix"><label>Tilbud:</label><span class="price-new"><?php echo $price; ?></span></div>
                        <?php } ?>
                    </div>
                    <div class="sttProdcuct">
                        <?php if($stock){ ?>
                            <img src="catalog/view/theme/<?php echo $template; ?>/images/icon_checkgreen.png">
                        <?php }else{ ?>
                            <img src="catalog/view/theme/<?php echo $template; ?>/images/icon_del.png">
                        <?php } ?>
                    </div>
                </div>
                <form action="<?php echo str_replace('&', '&amp;', $action); ?>" method="post" enctype="multipart/form-data" id="product">
                    <div class="r-select clearfix">
                        <div class="wrap-antal">
                           <label>Antal</label>
                           <input type="text" id="product_qty" class="number" name="quantity" value="1" size="2" maxlength="2"/>
                        </div>
                        <?php foreach ($options as $option) { ?>
                            <div class="wrap-select-size">
                                <label><?php echo $option['name'] ?></label>
                                <select id="product_option_<?php echo $option['option_id']; ?>" class="product_option_list" name="option[<?php echo $option['option_id']; ?>]">
                                    <option value="none" rel="0" alt="<?php echo $sku; ?>">Vælg <?php echo $option['name'] ?></option>
                                    <?php foreach ($option['option_value'] as $option_value) { ?>
                                        <option value="<?php echo $option_value['option_value_id']; ?>" rel="<?php echo $option_value['price']; ?>" alt="<?php echo $option_value['option_number']; ?>" shape="<?php echo $option_value['quantity']; ?>"><?php echo $option_value['name']; ?></option>
                                    <?php } ?>
                                </select>
                                <a class="sizeguide" data-reveal-id="ppSizeGuide" data-animation="none" href="#">STØRRELSESGUIDE</a>
                            </div>
                        <?php } ?>

                        <input type="hidden" name="product_id" value="<?php echo $product_id; ?>"/>
                        <input type="hidden" name="redirect" value="<?php echo str_replace('&', '&amp;', $redirect); ?>"/>
                        <input type="hidden" name="product_category" value="<?php echo $product_category; ?>"/>
                    </div>
                    <div class="r-button clearfix">
                        <?php if($stock){ ?>
                            <a class="btn btnAddtocard" href="javascript:void(0);" onclick="addTocart();">Læg i kurv</a>
                        <?php }?>
                        <a class="btn btnInfoProd fancybox" href="#ppQuestion">Info om dette produkt</a>
                    </div>
                </form>
            </div>
            <!--col-detail-right-->
        </div>
        <!--text-content-->

        <?php if(!empty($products)){ ?>
            <div class="eachBox wrap-list-prod product-relative clearfix">
                <h4>Relaterede produkter</h4>
                <ul class="listProd">
                    <?php $count = count($products); $i = 1; ?>
                    <?php foreach($products as $related_item){ ?>
                        <li>
                            <a href="#" class="product">
                                <?php if($related_item['discount']){ ?>
                                    <div class="sale-off"><span>-<?php echo $related_item['rate_discount']; ?></span><span>%</span></div>
                                <?php } ?>
                                <a class="prod-img" href="<?php echo $related_item['href']; ?>">
                                    <img src="<?php echo $related_item['thumb']; ?>"/>
                                </a>
                                <div class="prod-name"><p><?php echo $related_item['name']; ?></p></div>

                                <?php if($related_item['discounts']){ ?>
                                    <div class="prod-price"><span class="price-old"><?php echo $related_item['price']; ?></span><span class="price-new"><?php echo $related_item['discount']; ?></span> </div>
                                <?php }else{ ?>
                                    <div class="prod-price"><span class="price-old"><?php echo $related_item['price']; ?></span></div>
                                <?php } ?>

                                <?php if($related_item['options'] && false){ ?>
                                    <div class="product_sizes_popup">
                                        <?php
                                        $op = 0;
                                        foreach($related_item['options'] as $options){
                                            $option_data = '';
                                            foreach($options['option_value'] as $option_item){
                                                $option_data .=  $option_item['name'] . ', ';
                                            }
                                            $option_data = trim($option_data, ', ');
                                        ?>
                                            <p class="header <?php echo ($op > 0 ? ' p5t' : ''); ?>"><?php echo (strcasecmp($options['name'], 'Størrelse') == 0) ? 'Størrelser' : $options['name'] ?></p>
                                            <p class="data"><?php echo $option_data ?></p>
                                            <?php $op++; ?>
                                        <?php } ?>
                                    </div>
                                <?php } ?>

                                <a href="<?php echo $related_item['href']; ?>" class="btn btnBestil" >Bestil Nu</a>
                                <div class="see-inc"><a class="hastool" title="<?php echo $shipping_note;?>">Se pris inkl. fragt/gebyr</a></div>
                            </a>
                        </li>
                    <?php } ?>
                </ul>
            </div>
            <!--wrap-list-prod-->
        <?php } ?>
    </div>
    <!--w-content-->

    <?php echo $services; ?>
    <?php echo $newsletter ?>

    <?php if(($size_guide != '') && ($size_guide != 'none') && false){ ?>
        <div id="ppSizeGuide" class="reveal-modal">
            <div class="wrap-pp wrap-size-guide">
                <h4>Størrelsesguide</h4>

                <?php
                $except_list = array(
                'hempel_farvekort'  => 'Hempel Farvekort',
                'ox_on' => 'OX-ON Størrelsesskema',
                );
                ?>

                <?php if(array_key_exists($size_guide, $except_list)){ ?>
                    <a target="_blank" style="font-size: 14px; color: #0C4F7D;" href="<?php echo $download_link . $size_guide . '.pdf'; ?>">Hent:&nbsp;<?php echo $except_list[$size_guide]; ?>&nbsp;PDF fil</a>
                <?php }else{ ?>
                    <?php echo $size_guide_data; ?>
                <?php } ?>
            </div>
            <a class="close-reveal-modal">&#215;</a>
        </div>
    <?php } ?>

    <!-- Tell friend -->
    <?php echo $tellfriend; ?>
    <!-- Send a question -->
    <?php echo $send_question; ?>


<script type='text/javascript' src='catalog/view/theme/<?php echo $template; ?>/js/product.js'></script>
<script type="text/javascript">
    function addTocart(){
        var in_stock = '<?php echo $stock;?>';
        var numeric_filter = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)|(^-?\d*$)/;
        if(in_stock <= 0){
            showPopup('Dette produkt er ikke nok mængde på lager.');
            //jQuery('#add_product_error').html('<span id="option_error" style="">Dette produkt er ikke længere på lager.</span>');

            return false;
        }

        var size_qty = jQuery("select[id*='product_option_'] option:selected").attr('shape') * 1;
        var qty = jQuery('#product_qty').val();
        if(in_stock < qty || size_qty < qty){
            showPopup('Dette antal er ikke på lager. Ring 48301699 eller send os en MAIL på <a style="color:#4CD7FF;" href="mailto:webshop@havhokeren.dk">webshop@havhokeren.dk</a>.')

            jQuery('#product_qty').val(1);

            return false;
        }

        var valid_attribute = jQuery('select.product_option_list').length > 0;
        var option_name = '';
        jQuery('select.product_option_list').each(function(){
            if(jQuery(this).val() == 'none'){
                valid_attribute = false;

                if(option_name == ''){
                    option_name = jQuery(this).siblings('label').eq(0).html();
                    option_name = option_name.replace(':', '');
                    option_name = option_name.replace(' ', '');
                }

            }
        });

        if(!valid_attribute && (option_name != '')) {
            //jQuery('#add_product_error').html('<span id="option_error" style="">Vælg venligst en "' + option_name + '"</span>');
            //jQuery('#add_product_error').show();
            showPopup('Vælg venligst en "' + option_name + '"!')

            return false;
        }

        var quantity = jQuery('#product_qty').val() * 1;
        if (quantity <= 0 || !numeric_filter.test(jQuery('#product_qty').val())){
            //jQuery('#add_product_error').html('<span id="option_error" style="">Angiv mængde (kun acceptere antal)</span>');
            //jQuery('#add_product_error').show();
            showPopup('Angiv mængde (kun acceptere antal)');

            return false;
        }
        else {
            jQuery('#add_product_error').html('');
            jQuery('#add_product_error').hide();
        }

        jQuery.ajax({
            type: 'post',
            url: 'index.php?route=module/cart/refreshCart',
            dataType: 'html',
            data: jQuery('#product :input'),
            success: function (html) {
                jQuery('#cart_info').html(html);
            },
            complete: function () {
            }
        });

    }
</script>

<!-- Footer -->
<?php echo $footer; ?>